package xyz.robinbingo.leetcode.a20.b05.c21;

import java.util.Arrays;

public class Solution {
    public String longestPalindrome(String s) {
        int length = s.length();
        String result = "";
        boolean[][] dp = new boolean[length][length];
        for (int l = 1; l <= length; l++) {
            for (int i = 0; i <= length - l; i++) {
                int j = i + l - 1;
                if (l == 1) {
                    dp[i][j] = true;
                } else if (l == 2) {
                    dp[i][j] = s.charAt(i) == s.charAt(j);
                } else {
                    dp[i][j] = dp[i + 1][j - 1] && s.charAt(i) == s.charAt(j);
                }
                if (dp[i][j] && l > result.length()) {
                    result = s.substring(i, i + l);
                }
            }
        }
        System.out.println(Arrays.deepToString(dp));
        return result;
    }
}